package com.artpri.dao.impl;

import java.util.List;

import com.artpri.dao.ShopCartDao;
import com.artpri.model.ShopCart;

/**
 * 
 * @author ZhangSi
 *
 */
public class ShopCartDaoImpl extends HibernateDaoImpl<ShopCart> implements ShopCartDao{

	@Override
	public boolean checkShopCartExists(Integer userNum, Integer goodsNum) {
		int i = findCount("select count(*) from ShopCart s where s.userNum=?0 and s.goodsNum=?1", userNum, goodsNum);
		return i == 0 ? false : true;
	}

	@Override
	public void delete(List<Integer> cartIds) {
		Object[][] params = new Object[cartIds.size()][1];
		
		for(int i = 0; i < cartIds.size(); i++) {
			Object[] param = new Object[]{cartIds.get(i)};
			params[i] = param;
		}
		
		updateBatch("delete from shop_cart where cart_id=?", params);
	}

}
